package com.hxzy.shop.controller;

import com.github.pagehelper.PageInfo;
import com.hxzy.shop.common.dto.auth.req.AccountListReq;
import com.hxzy.shop.common.dto.auth.req.AddAccountReq;
import com.hxzy.shop.common.dto.auth.req.EditAccountReq;
import com.hxzy.shop.common.dto.auth.req.RoleListReq;
import com.hxzy.shop.common.dto.auth.resp.AccountDetailResp;
import com.hxzy.shop.common.dto.auth.resp.AccountListResp;
import com.hxzy.shop.common.dto.auth.resp.RoleListResp;
import com.hxzy.shop.service.impl.AdminAccountServiceImpl;
import com.hxzy.shop.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 功能描述
 *
 * @author tonneyyy
 */
@RestController
@Api(tags = "后台用户账户管理")
@RequestMapping("/ums/account")
public class AdminAccountController {


    @Autowired
    private AdminAccountServiceImpl adminAccountService;


    @ApiOperation(value = "总店账户分页")
    @GetMapping(value = "/list")
    public Result<PageInfo<AccountListResp>> roleList(@Valid AccountListReq req) {
        return Result.success( adminAccountService.search(req));
    }

    @ApiOperation(value = "新增账户")
    @PostMapping
    public Result<Object> addAccount(@RequestBody @Valid AddAccountReq req){
        int count=this.adminAccountService.addAccount(req);
        return count>0? Result.success():Result.failed();
    }

    @ApiOperation(value = "帐号详情", notes = "帐号详情")
    @GetMapping(value = "/{accountId}")
    public Result<AccountDetailResp> accountDetail(@PathVariable(value = "accountId") Long accountId) {
        return Result.success(this.adminAccountService.accountDetail(accountId));
    }

    @ApiOperation(value = "修改账户")
    @PutMapping
    public Result<Object> editAccount(@RequestBody @Valid EditAccountReq req){
        int count=this.adminAccountService.editAccount(req);
        return count>0? Result.success():Result.failed();
    }
}
